package com.itheima.CSM_bacK.aaaControllers;

import com.itheima.CSM_bacK.aabServices.Serv.CheckGroupServ;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.DTO.DTOcGroupA;
import com.itheima.pojo.DTO.DTOcGroupE;
import com.itheima.pojo.VO.VOcGroupFA;
import com.itheima.pojo.VO.VOcGroupFBI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
//@PreAuthorize("hasAnyAuthority('aUser')")
public class CheckGroupController {
    @Autowired
    private CheckGroupServ checkGroupServ;

    @PostMapping("/add")
    public Result add(@RequestParam List<Integer> checkitemIds, @RequestBody DTOcGroupA kk) {
        checkGroupServ.add(checkitemIds,kk);
        return new Result(true,"新增检查组成功");

    }

    @GetMapping("/deleteById")
    public Result deleteById(Integer id) {
        checkGroupServ.deleteById(id);
        return new Result(true,"删除检查组成功");
    }

    @GetMapping("/findCheckGroupIdsBySetmealId")
    public Result findCheckGroupIdsBySetmealId(Integer setmealId) {
        List<Integer> kks = checkGroupServ.findCheckGroupIdsBySetmealId(setmealId);
        return new Result(true,"查询检查组成功",kks);
    }

    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean kk) {
        PageResult vvo = checkGroupServ.findPage(kk);
        return vvo;

    }

    @PostMapping("/edit")
    public Result edit(@RequestParam List<Integer> checkitemIds,@RequestBody DTOcGroupE kk) {

        checkGroupServ.edit(checkitemIds,kk);
        return new Result(true,"编辑检查组成功");

    }
    @GetMapping("/findAll")
    public Result findAll() {
        List<VOcGroupFA> vvo = checkGroupServ.findAll();
        return new Result(true,"查询检查组成功",vvo);
    }

    @GetMapping("/findById")
    public Result findById(Integer id) {
        VOcGroupFBI vvo = checkGroupServ.findById(id);
        return new Result(true,"查询检查组成功",vvo);
    }



}
